# 标准化数据模块
from sklearn import preprocessing
import numpy as np

# 将资料分割成train与test的模块
from sklearn.model_selection import train_test_split

# 生成适合做classification资料的模块
from sklearn.datasets.samples_generator import make_classification

# Support Vector Machine中的Support Vector Classifier
from sklearn.svm import SVC

# 可视化数据的模块
import matplotlib.pyplot as plt

a = np.array([[10, 2.7, 3.6],
              [-100, 5, -2],
              [120, 20, 40]], dtype=np.float64)

# 将 a 标准化输出
print(preprocessing.scale(a))

# 生成具有2种属性的300笔数据
X, y = make_classification(
    n_samples=300, n_features=2,
    n_redundant=0, n_informative=2,
    random_state=22, n_clusters_per_class=1,
    scale=100)
X = preprocessing.scale(X)
train_X, test_X, train_y, test_y = train_test_split(X, y, test_size=0.3)

model = SVC(kernel='linear', C=1.0)
model.fit(train_X, train_y)

w = model.coef_[0]
a = -w[0] / w[1] # 斜率
fx = a * train_X - model.intercept_[0]/w[1]

print(model.score(test_X, test_y))


# 可视化数据
plt.scatter(X[:, 0], X[:, 1], c=y)
plt.plot(train_X, fx, 'k-')
plt.show()
